package com.lr.server.demo1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;

/*
 * 创建服务器并启动
 */
public class Server {
	
	private ServerSocket server;

	public static void main(String[] args) {
		Server server = new Server();
		server.start();
	}
	
	public void start(){
		try {
			server = new ServerSocket(8888);
			this.recieve();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void recieve(){
		BufferedReader br = null;
		try {
			Socket socket = server.accept();
			br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
			String line = null;
			StringBuilder sb = new StringBuilder();
			while((line = br.readLine()).length() > 0){
				if(null == line){
					break;
				}
				sb.append(line);
				sb.append("\n");
			}
			System.out.println(sb.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			IOUtil.IOClose(br);
		}
	}
	
	public void stop(){
		
	}

}
